<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html class="win-frame">
<head>
<title>${name_china}管理-编辑${name_china}</title>
<%@include file="/common/head.jsp" %>

</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
            <span class="split"></span>
            <span>编辑${name_china}</span>
        </div>
        <a id="goBack" class="btn-return distance-left" href="javascript:;"><i class="icon icon-arrow-left"></i>返回上级</a>
    </div>
    <div class="page-title-border"></div>
</div>

<div class="search-field">
    <span class="field-cont">
        <span class="field-cont-title">用户名</span>
        <input type="text" class="summer-input" id="userNickName"/>
    </span>
     <span class="field-cont">
        <span class="field-cont-title">用户电话</span>
        <input type="text" class="summer-input" id="userPhone"/>
    </span>
     <span class="field-cont">
        <span class="field-cont-title">用户关系类型</span>
        <input type="text" class="summer-input" id="levelDesc"/>
    </span>
    
    <span class="field-btn-wrapper">
        <a id="search" class="btn btn-primary btn-icon wave distance-right"><i class="icon icon-search"></i></a>
        <a id="reset" class="btn btn-icon wave wave-dark"><i class="icon icon-refresh"></i></a>
    </span>
</div>
<div id="t-wrap">
    <table class="summer-datagrid" id="dataList">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	   
	    <thead>
		    <tr>
		    	<th>用户ID</th>		        
		        <th>用户名</th>
		        <th>用户级别</th>
		        <th>用户电话</th>
		        <th>用户来源</th>
		        <th>活跃状态</th>
		        <th>总消费金额</th>
		    </tr>
	    </thead>
    </table>
</div>
<script>
    
  var   editData,
        permission = CommonUtil.getPermission('${name_english}');
  //请求url
	var CONST_URL = {
		LIST: basePath + '${common_url}list',
	   	INIT_ADD: basePath + "${common_url}initAdd",
	   	INIT_EDIT: basePath + "${common_url}initEdit",
	   	INIT_VIEW: basePath + "${common_url}initView",
	   	DEL: basePath + "${common_url}del",
	   	INIT_LEVEL: basePath + '${common_url}initLevel',
	   	INIT_MAIN : basePath + "${common_url}init"
	};
  //查看
    $(function () {
    	editData = ${editData};
        createTable();	
      //初始化下拉选项
    	    //下拉初始化
   	   
   	 $('#levelDesc').combobox({
         valueField : 'code',
         textField : 'name',
         url : COMMON_URL.getCode + '?type=T_DM_T_USERS_MALL_LEVEL_DESC'
     });
      //返回按钮
		$('#backBtn, #goBack').on('click', backMain);
		// 查询按钮
        $('#search').on('click', reloadTable);
        //重置按钮
        $('#reset').on('click', function () {
        	//重置文本框的值
        	$('#userNickName').val('');
        	$('#userPhone').val('');
        	$('#levelDesc').combobox('clear');
        	//levelDesc
        	//$('#stopTime').val('');
        	
        	reloadTable();
        });
        //删除
		$('#t-wrap').on('click', 'a[data-permit="${name_english}:del"]', function() {
			var $this = $(this),
			    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
			$.sdialog({
				type: 'confirm',
				msg: '您确定要删除选中的记录吗?',
				onConfirm: function(result) {
				    if (result) {
				    	$.sajax({
			                url : CONST_URL.DEL + "?id=" + id,
			                onLoadSuccess : function() {
			                	 $.stip({
                	                type:'ok',//显示类型 有info、 ok、 danger
                	                text: '删除成功！'    
			                	});
			                	reloadTable();  
			                }
			            });
				    		
				    }	
				}
			});
		});
		});  
  
	//返回主页面
	function backMain() {
		window.location.href = CONST_URL.INIT_MAIN;
	}
	
	
	// 重新加载表格
	function reloadTable() {
		$('#dataList').datagrid('reload', {
			ajax : {
				param : {
					"userNickName" : trimSpace($('#userNickName').val()),
					"userPhone" : trimSpace($('#userPhone').val()),
            		"levelDesc":$('#levelDesc').combobox('getValue')
				//"startTime": trimSpace($('#startTime').val()),
				//"stopTime": trimSpace($('#stopTime').val())
				}
			}
		});
	}
	
	//创建表格
	function createTable() {
		$('#dataList').datagrid({
			ajax : {
				url : CONST_URL.INIT_LEVEL + "?id=" + editData.id,
				//url : CONST_URL.DEL + "?id=" + id
				param : {
					"userNickName" : trimSpace($('#userNickName').val()),
					"userPhone" : trimSpace($('#userPhone').val())
					//"levelDesc":$('#levelDesc').combobox('getValue')
				//"startTime": trimSpace($('#startTime').val()),
				//"stopTime": trimSpace($('#stopTime').val())
				}
			},
			columns : [ {
				field : 'id',
				hidden : true
			}, {
				field : 'id'
			}, {
				field : 'userNickName'
			}, {
				field : 'levelDesc'
			}, {
				field : 'userPhone'
			}, {
				field : 'laiyuan'
			}, {
				field : 'isActive'
			}, {
				field : 'totalComsum'
			}

			]
		});
	}
	
</script>
</body>
</html>